package org.teremail.smtp.commands;


import java.util.List;

import org.teremail.smtp.SMTPCommandFactory;
import org.teremail.smtp.SMTPSession;


public class DATACommand extends SMTPCommand {
    
    private static final String MSG_351 = "354 Start mail input; end with <CRLF>.<CRLF>";
    
    public DATACommand() {
        super("DATA", EMPTY);
    }
    
    @Override
    public void process(SMTPSession session) {
        if (session.getSender() == null) {
            session.write(MSG_503);
        } else if (session.getRecipients().size() == 0) {
            session.write(MSG_554);
        } else {
            session.setDataMode(true);
            session.write(MSG_351);
        }
    }

    public static final SMTPCommandFactory FACTORY = new SMTPCommandFactory() {
        public SMTPCommand create(List<String> parameters) {
            // TODO, is the data command immutable (reuse instance)?
            return new DATACommand();
        }
    };

}
